package com.share.bigdata.flink.countword;

import com.share.bigdata.flink.countword.app.CountWordApp;
import com.share.bigdata.flink.countword.app.EventWindowsCountWordApp;
import com.share.bigdata.flink.countword.app.ProcessWindowsCountWordApp;

import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.List;

public class MainCountWord {
    public static void main(String[] args) {
        List<Class> list = new LinkedList<>();
        list.add(EventWindowsCountWordApp.class);
        list.add(ProcessWindowsCountWordApp.class);
        list.add(CountWordApp.class);


        int i = 0;
        for (Class clz : list) {
            System.out.println(i + "\t" + clz.getName());
            i++;
        }

        try {
            i = new Integer(args[0]);
            if (i >= list.size()) {
                i = 0;
            }
        } catch (Exception e) {
            i = 0;
        }

        if (list.isEmpty()) {
            i = -1;
        }

        String status = "";
        if (i < 0) {
            status = "参数异常";
        } else {
            Class clazz = list.get(i);
            System.out.println("将执行:" + clazz.getName());
            Object o = null;
            try {
                o = clazz.newInstance();
                Method main = clazz.getMethod("main", new Class[]{String.class});
                Object invoke = main.invoke(o, args);
                status = "执行完毕";
            } catch (Exception e) {
                status = e.getMessage();
            }
        }
        System.out.println("执行状态status=" + status);
        return;
    }
}
